<template>
	<view>
		<view class="scroll-view-container">
			<!-- 左侧滚动区域 -->
			<scroll-view scroll-y="true" :style="{height:wh+'px'}" class="left-scroll-view">
				<!-- block 是一个包裹性质的容器 但是不在页面当中渲染 -->
				<block v-for="(item,index) in cateList" :key="index">
					<view :class="['left-scroll-view-item',index == active ? 'active':'']" @click="activeChange(index)">{{item.cat_name}}</view>
				</block>
			</scroll-view>
			
			<!-- 右侧滚动区域 -->
			<scroll-view scroll-y="true" :style="{height:wh+'px'}" class="right-scroll-view" :scroll-top="scrollTop">
				<view class="cate-level2" v-for="(item2,index) in cateLevelTwo" :key="index">
					<view class="cate-level2-title">/{{item2.cat_name}}/</view>
					
					<!-- 三级列表 item2.children -->
					<view class="cate-level3-list">
						<view class="cate-level3-item" v-for="(item3,index3) in item2.children" :key="index3" @click="goGoodsList(item3)">
							<image src="../../static/logo.png" mode="">
								<text>{{item3.cat_name}}</text>
							</image>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {categoriesData} from '@/api/cate_request.js'
	export default {
		data() {
			return {
				wh:0,
				//分类中的数据
				cateList:[],
				//下标为0
				active:0,
				//二级分类列表的初始值
				cateLevelTwo:[],
				//滚动条距离顶部的位置
				scrollTop:0
			}
		},
		onLoad(){
			//获取当前系统的信息
			const sysInfo = uni.getSystemInfoSync();
			//窗口的可用高度
			this.wh = sysInfo.windowHeight;
			//调用函数发送网络数据请求
			this.getCateList();
		},
		methods:{
			async getCateList(){
				//发起请求
				const {data:res} = await categoriesData();
				console.log(res);
				//失败 
				if(res.meta.status !== 200) return uni.$showMsg();
				//成功之后将其赋给data中的初始值数据
				this.cateList = res.message;
				//二级分类列表
				this.cateLevelTwo = res.message[0].children;
			},
			activeChange(index){
				this.active = index;
				//点击下边   二级列表当中的下标
				this.cateLevelTwo = this.cateList[index].children;
				//当点击之后导航切换   
				//this.srcollTop 0  scroll-view  scroll-top 0 滚动 它变换 this.scrollTop
				//0 1之间切换
				this.scrollTop = this.scrollTop === 0 ? 1 : 0;
			},
			goGoodsList(item3){
				uni.navigateTo({
					url:'/subpkg/goods_list/goods_list?catd' + item3.cat_id
				})
			}
		}
	}
</script>

<style lang="scss">
.scroll-view-container{
	display: flex;
	.left-scroll-view{
		width: 240rpx;
		.left-scroll-view-item{
			color: #fff;
			font-size: 15px;
			line-height: 120rpx;
			background-color: #000;
			text-align: center;
			&.active{
				background-color: green;
				//竖线 
				//让块元素垂直居中
				position: relative;
				&::before{
					content: '';
					display: block;
					width: 6rpx;
					height: 60rpx;
					background-color: red;
					position: absolute;
					left: 0;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}
	}
	.right-scroll-view{
		.cate-level2{
			.cate-level2-title{
				font-size: 15px;
				font-weight: 700;
				text-align: center;
				padding: 15px 0;
			}
			.cate-level3-list{
				display: flex;
				flex-wrap: wrap;
				.cate-level3-item{
					width: 33.33%;
					display: flex;
					//图片在上字在下   调转为侧轴方向
					flex-direction: column;
					align-items: center;
					image{
						width: 120rpx;
						height: 120rpx;
					}
				}
			}
		}
	}
}
</style>
